/**
	集群相关接口
 */
package hard

import (
	. "bc/util"
	"strings"
)

type cluster struct {

}
/**
	创建一个集群
 */
func CreateCluster(h map[string]string,b string) (string,error) {

	url := Config.Zstack.ApiUrl + "/v1/clusters"
	res,err := Curl.Url(url).Header(h).Body(b).POST()
	return res,err

}
/**
	删除一个集群
 */
func DeleteCluster(uuid string,del string,h map[string]string,b string) (string,error) {

	url := Config.Zstack.ApiUrl + "/v1/clusters/{uuid}?deleteMode={deleteMode}"
	url = strings.Replace(url,"{uuid}",uuid,1)
	url = strings.Replace(url,"{deleteMode}",del,1)
	res,err := Curl.Url(url).Header(h).Body(b).DELETE()
	return res,err

}
/**
	查询集群
 */
func QueryCluster(uuid string,h map[string]string) (string,error) {

	url := Config.Zstack.ApiUrl + "/v1/clusters/{uuid}"
	url = strings.Replace(url,"{uuid}",uuid,1)
	res,err := Curl.Url(url).Header(h).GET()
	return res,err

}
/**
	更新集群
 */
func UpdateCluster(uuid string ,h map[string]string,b string) (string,error) {

	url := Config.Zstack.ApiUrl + "/v1/clusters/{uuid}/actions"
	url = strings.Replace(url,"{uuid}",uuid,1)
	res , err:= Curl.Url(url).Header(h).Body(b).PUT()
	return res,err

}
/**
	改变一个集群的可用状态
 */
func ChangeClusterState(uuid string,h map[string]string,b string) (string,error) {

	url := Config.Zstack.ApiUrl + "/v1/clusters/{uuid}/actions"
	url = strings.Replace(url,"{uuid}",uuid,1)
	res,err := Curl.Url(url).Header(h).Body(b).PUT()
	return res,err

}
/**
	升级集群内物理机的操作系统
 */
func UpdateClusterOS(uuid string,h map[string]string,b string) (string,error) {

	url := Config.Zstack.ApiUrl + "/v1/clusters/{uuid}/actions"
	url = strings.Replace(url,"{uuid}",uuid,1)
	res ,err:= Curl.Url(url).Header(h).Body(b).PUT()
	return res,err

}
var Cluster = &cluster{}
